<template>
  <div>
    <!-- 头部组件 -->
    <!-- <Top title="水珠钱包">
        <span slot="icon">
          <i class="iconfont icon-wenhao" @click="goHelpcenter"></i>
        </span>
      </Top> -->
    <div class="recommend">
      <!-- 推荐列表 -->
      <div class="recommend-list" v-for="(item,index) in productList" :key="index" @click="goChildPage(item.platformId)">
        <div class="recommend-list-logo">
          <div class="recommend-list-logo-img">
            <img :src="item.logo" />
          </div>
        </div>
        <div class="recommend-list-content">
          <div class="title">{{item.abbreviation}}</div>
          <span class="badge" v-for="(itemS,idx) in item.label" :key="idx">{{itemS}}</span>
          <div class="money">
            <span class="money-rmb">¥</span>
            <span class="money-num">{{item.quato}}</span>
          </div>
        </div>
        <div class="recommend-list-icon">
          <i class="iconfont icon-jiankuohaoxiyou"></i>
        </div>
      </div>
      <!-- 更多贷款 -->
      <div class="look-more" @click="lookMore" v-if="showMore">更多贷款&nbsp;
        <i class="iconfont icon-zhankaifuzhi"></i>
      </div>
      <!-- 没有更多了 -->
      <div class="no-more" v-if="!showMore">
        <span>没有更多了</span>
        <p>没有找到合适的产品？点击这
          <a @click="quickMatch">快速匹配</a>
        </p>
      </div>
    </div>
    <!-- <Model title="您真的要离开吗？" content="内容" leftName="返回" rightName="继续申请" v-on:leftClick="leftBtn" v-on:rightClick="rightBtn" :showModel="productModel"></Model> -->
  </div>
</template>
<script>
// 头部组件引入
import Top from '../../components/Header'
//loading组件引入
import { Indicator } from 'mint-ui';
// 带有单选的模态框组件引入
import Model from '../../components/Modelcheck'
export default {
  name: 'recommendproduct',
  components: { Top, Model },
  data() {
    return {
      productList: [], //产品列表
      productModel: true, //产品模态框显示与否
      pageNum: 1, //分页的页数
      showMore: true //是否显示'显示更多'
    }
  },
  methods: {
    goHelpcenter() {
      // 点击进入帮助中心页面
      this.$router.push({ path: '/helpcenter' })
    },
    goChildPage(platformId) {
      // 记录访问次数
      // 访问类型(1首页浏览量,2首页bannar点击量,3注册登录点击量,4首页产品点击量,5推荐产品点击量,6详情分享点击量,7提前花点击量)
      let borrowerId = window.sessionStorage.getItem('borrowerId');
      let type = 5;
      let invData = {
        borrowerId: borrowerId,
        platformId: platformId,
        type: type
      }
      // this.$router.push({path:url})
      this.$http.post('/loansupermarket-app/personal/saveCustomerPlatformVisitInfo.do', invData)
        .then((response) => {
          var resBody = response.body;
          // console.log(resBody)
          if (resBody.code == '000') {
            // console.log('访问记录已添加！');
          }
        });
      //进去详情页  platformId传到子页面,定位产品详情
      this.$router.push({ path: '/loanplatformdetail', query: { platformId: platformId } })
    },
    leftBtn() {
      // 关闭模态框
      this.productModel = false;
    },
    // 点击申请
    rightBtn() {
      // 点击产品,进入产品详情页
      this.goChildPage(this.platformId)
    },
    getList() {
      /* 
      @params
      @function 调用产品列表接口
    */
      this.$http.post('/loansupermarket-app/platform/getRecommendPlatformList.do?pageNum=' + this.pageNum + '&&pageSize=6')
        .then((response) => {
          var resBody = response.body;
          if (resBody.code == '000') {
            setTimeout(function(){
              Indicator.close();
            },500)
       
            // 数组拼接
            if (resBody.result.length != 0) {
              this.productList = this.productList.concat(resBody.result);
            }
            //判断是否还有更多
            if (resBody.result < 6) {
              this.showMore = false;
            }
            // 如果label为string，那么就拆分成数组
            this.productList.forEach(function (element) {
              if (typeof (element.label) == "string") {
                element.label = element.label.split(',');
              }
            });
          }
        })
    },
    lookMore() {
      // 点击加载更多,显示loading
      Indicator.open('加载中···');
      this.pageNum += 1;
      this.getList();
    },
    quickMatch() {
      let borrowerId = window.sessionStorage.getItem('borrowerId');
      let postData = { borrowerId: borrowerId };
      // 判断登录没登录
      this.$http.post('/loansupermarket-app/personal/getCustomerBaseInfo.do', postData)
        .then((response) => {
          var resBody = response.body;
          // console.log(resBody)
          if (resBody.code == '444') {
            this.$router.push({ path: '/login' })
          } else if (resBody.code == '000') {
            this.$router.push({ path: '/applyloan' })
          }
        });
    }
  },
  mounted() {
    // 页面加载进来第一次实例化
    this.getList();
  }
}
</script>
<style lang="scss">
@import '../../scss/variable/base.scss';
.recommend {
  // margin-top: 1rem;
  margin-top: -0.2rem;
  margin-bottom: 1.2rem;
  width: 100%;
  box-sizing: border-box;
  padding: 0.2rem 0.4rem;
  &-list {
    box-shadow: 1px 1px 6px rgba(0, 0, 0, 0.05);
    margin-top: 0.28rem;
    text-align: left;
    width: 100%;
    background: #fff;
    border-radius: 4px;
    overflow: hidden;
    display: flex;
    &-logo {
      flex: 2.5;
      &-img {
        width: 1.2rem;
        height: 1.2rem;
        margin: 0.8rem auto;
        border-radius: 50%;
        overflow: hidden;
        img {
          width: 100%;
          height: 100%;
        }
      }
    }
    &-content {
      flex: 8;
      box-sizing: border-box;
      .title {
        line-height: 1.15rem;
        font-size: 0.42rem;
        font-family: PingFangSC-Regular, sans-serif;
      }
      .badge {
        display: inline-block; // width: 1.5rem;
        padding: 0 0.2rem;
        min-width: 1.1rem;
        line-height: 0.475rem;
        height: 0.44rem;
        text-align: center;
        border: 1px solid $primaryColor;
        color: $primaryColor;
        border-radius: 0.24rem;
        margin-right: 0.1rem;
      }
      .money {
        line-height: 1.1rem;
        height: 0.9rem;
        &-rmb {
          font-size: 0.6rem;
          color: $redColor;
        }
        &-num {
          font-size: 0.75rem;
          color: $redColor;
          margin-left: 0.1rem;
          font-family: PingFangSC-Regular, sans-serif;
        }
      }
    }
    &-icon {
      flex: 1.5;
      line-height: 2.5rem;
      text-align: center;
      .iconfont {
        font-size: 0.45rem;
        vertical-align: -11%;
      }
    }
  }
  .look-more {
    margin-top: 0.4rem;
    font-size: 0.4rem;
    color: $iconColor;
    .iconfont {
      color: $iconColor;
      vertical-align: 4%;
    }
  }
  .no-more {
    margin-top: 0.3rem;
    font-size: 0.34rem;
    span {
      color: $iconColor;
    }
    p {
      span {
        color: $iconColor;
      }
      a {
        color: $primaryColor;
        text-decoration: underline;
      }
    }
  }

}

</style>


